define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'byd_order_return/index' + location.search,
                    //add_url: 'byd_order_return/add',
                    edit_url: 'byd_order_return/edit',
                    state00_url: 'byd_order_return/index?search=&state=0',
                   // del_url: 'byd_order_return/del',
                    multi_url: 'byd_order_return/multi',
                   // import_url: 'byd_order_return/import',
                    table: 'byd_shop_order',
                }
            });

            var table = $("#table");
                        var opt = {
                    url: "byd_order_return/index?search=",
                    silent: true,
                    query:{
                        filter:'{"state":0}'
                    }
                };  

            $(document).on('click', '.btn-state00', function () {
               opt.query.filter = '{"state":0}'; 
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state01', function () {
                opt.query.filter = '{"state":1}';           
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state02', function () {
                opt.query.filter = '{"state":2}';            
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state03', function () {
                opt.query.filter = '{"state":3}';            
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state04', function () {
                opt.query.filter = '{"state":4}';             
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state05', function () {
                opt.query.filter = '{"state":5}';             
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state06', function () {
                opt.query.filter = '{"state":6}';             
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state07', function () {
                opt.query.filter = '{"state":7}';            
                table.bootstrapTable('refresh',opt);
            });
            $(document).on('click', '.btn-state08', function () {
                opt.query.filter = '{"state":8}';            
                table.bootstrapTable('refresh',opt);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'orderid', title: __('Orderid'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'num', title: __('Num')},
                        {field: 'productid', title: __('Productid'), operate: 'LIKE'},
                        {field: 'addressid', title: __('Addressid')},
                        {field: 'special', title: __('Special'), operate: 'LIKE'},
                        {field: 'create_at', title: __('Create_at')},
                        {field: 'create_by', title: __('Create_by')},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"2":__('State 2'),"3":__('State 3'),"4":__('State 4'),"5":__('State 5'),"6":__('State 6'),"7":__('State 7'),"9 ":__('State 9 ')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'express', title: __('Express'), operate: 'LIKE'},
                        {field: 'expressorder', title: __('Expressorder'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'yf', title: __('Yf'), operate: 'LIKE'},
                       /* {field: 'specidsize', title: __('Specidsize'), operate: 'LIKE'},
                        {field: 'pl', title: __('Pl')},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'addressxq', title: __('Addressxq'), operate: 'LIKE'},
                        {field: 'deposit', title: __('Deposit'), operate:'BETWEEN'},
                        {field: 'gold', title: __('Gold'), operate:'BETWEEN'},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'tool_tee', title: __('Tool_tee'), operate: 'LIKE'},
                        {field: 'porderid', title: __('Porderid'), operate: 'LIKE'},
                        {field: 'content', title: __('Content'), operate: 'LIKE'},
                        {field: 'tuik_ly', title: __('Tuik_ly'), operate: 'LIKE'},
                        {field: 'bohui', title: __('Bohui'), operate: 'LIKE'},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});